﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Wicresoft.ARConnector;
using Wicresoft.Entity.Reconciliation;
using Wicresoft.Utility;

namespace Wicresoft.Reconciliation.DAL
{
    public class ComputerSystemDBOperate
    {
        private static readonly string ARServer = ConfigurationManager.AppSettings["ARServer"];
        private static readonly string ARUid = ConfigurationManager.AppSettings["ARUid"];
        private static readonly string ARPwd = ConfigurationManager.AppSettings["ARPwd"];

        private ARProxy<ComputerSystem> computerSystemARProxy;

        public void SaveSwitch(Switch sw)
        {
            computerSystemARProxy = new ARProxy<ComputerSystem>(ARUid, ARPwd, ARServer, string.Empty);
            ComputerSystem computerSystem = new ComputerSystem
            {
                Name = sw.Name,
                SerialNumber = sw.SerialNumber,
                Model = sw.Model,
                IP = sw.ManagementIP,
                HostName = sw.HostName,
                Configuration = sw.Configuration,
                InstalledLocation = sw.InstalledPostion,
                TagNumber = sw.TagNumber,
                DatasetId = sw.DatasetId,
                Item = NetworkType.Switch.ToString()
            };
            computerSystemARProxy.CreateEntry(computerSystem);
        }

        public void SaveRouter(Router rt)
        {
            computerSystemARProxy = new ARProxy<ComputerSystem>(ARUid, ARPwd, ARServer, string.Empty);
            ComputerSystem computerSystem = new ComputerSystem
            {
                Name = rt.Name,
                SerialNumber = rt.SerialNumber,
                Model = rt.Model,
                IP = rt.ManagementIP,
                HostName = rt.HostName,
                Configuration = rt.Configuration,
                InstalledLocation = rt.InstalledPostion,
                Type = rt.Type,
                TagNumber = rt.TagNumber,
                DatasetId = rt.DatasetId,
                Item = NetworkType.Router.ToString()
            };
            computerSystemARProxy.CreateEntry(computerSystem);
        }
        public void SaveWirelessController(WirelessController wc)
        {
            computerSystemARProxy = new ARProxy<ComputerSystem>(ARUid, ARPwd, ARServer, string.Empty);
            ComputerSystem computerSystem = new ComputerSystem
            {
                Name = wc.Name,
                SerialNumber = wc.SerialNumber,
                Model = wc.Model,
                IP = wc.ManagementIP,
                HostName = wc.HostName,
                Configuration = wc.Configuration,
                InstalledLocation = wc.InstalledPostion,
                Type = wc.Type,
                TagNumber = wc.TagNumber,
                DatasetId = wc.DatasetId,
                Item = NetworkType.WirelessController.ToString()
            };
            computerSystemARProxy.CreateEntry(computerSystem);
        }

        public void SaveVLAN(VLAN vlan)
        {
            computerSystemARProxy = new ARProxy<ComputerSystem>(ARUid, ARPwd, ARServer, string.Empty);
            ComputerSystem computerSystem = new ComputerSystem
            {
                Name = vlan.Name,
                VLANID = vlan.VLANID,
                DeviceHostName = vlan.DeviceHostName,
                SerialNumber = vlan.SerialNumber,
                IP = vlan.InterfaceIP,
                Mask = vlan.Mask,
                DefualtGateway = vlan.DefualtGateway,
                HSRP = vlan.HSRP,
                VRRP = vlan.VRRP,
                Type = vlan.Type,
                TagNumber = vlan.TagNumber,
                DatasetId = vlan.DatasetId,
                Item = NetworkType.VLAN.ToString()
            };
            computerSystemARProxy.CreateEntry(computerSystem);
        }
        public void SaveIPScope(IPScope ips)
        {
            computerSystemARProxy = new ARProxy<ComputerSystem>(ARUid, ARPwd, ARServer, string.Empty);
            ComputerSystem computerSystem = new ComputerSystem
            {
                Name = ips.Name,
                IPRange = ips.IPRange,
                Type =ips.Type,
                TagNumber = ips.TagNumber,
                DatasetId = ips.DatasetId,
                Item = NetworkType.IPScope.ToString()
            };
            computerSystemARProxy.CreateEntry(computerSystem);
        }
    }
}
